import type { CompanyInfo, DictItem, EmployeeInfo, OwnerFreightPageRequest, OwnerFreightPageResponse, PaymentTypeDict, ReceiptClaimRecordDetails, TenantDepartTree, UserListResponse } from './types/system'
import { http } from '@/http/http'

/**
 * 获取机构部门树【切换部门】
 * @returns 机构部门树
 */
export function getUserTenantDepartTree() {
  return http.get<TenantDepartTree>('/yngy-user/sys/tenant/userTenantDepartTree', {
    t: Date.now(),
  })
}

/**
 * 获取支付方式
 * @returns 支付方式列表
 */
export function getLogisticsPayTypeDict() {
  return http.get<DictItem[]>('/yngy-dictionary/sys/dict/getDictItems/logisticsPayType', {
    t: Date.now(),
  })
}

/**
 * 获取付款方式
 * @returns 付款方式列表
 */
export function getPaymentTypeDict() {
  return http.post<PaymentTypeDict[]>('/yngy-logistics/logistics/financePayChannel/listSysFinancePayChannel', {
    timestamp: Date.now(),
  })
}

/**
 * 获取发票类型
 * @returns 发票类型列表
 */
export function getInvoiceTypeDict() {
  return http.get<DictItem[]>('/yngy-dictionary/sys/dict/getDictItems/invoice_type', {
    t: Date.now(),
  })
}

/**
 * 获取运输类型
 * @returns 运输类型列表
 */
export function getLogisticsFreightTypeDict() {
  return http.get<DictItem[]>('/yngy-dictionary/sys/dict/getDictItems/logistics_freight_type_dict', {
    t: Date.now(),
  })
}

/**
 * 获取审批状态字典
 * @returns 审批状态列表
 */
export function getBpmTaskStatusDict() {
  return http.get<DictItem[]>('/yngy-dictionary/sys/dict/getDictItems/bpm_task_status', {
    t: Date.now(),
  })
}

/**
 * 获取本方结算主体
 * @returns 结算主体列表
 */
export function queryCompanyNew() {
  return http.get<CompanyInfo[]>('/yngy-base/ownCompany/queryCompanyNew', {
    t: Date.now(),
  })
}

/**
 * 获取员工列表
 * @param params 查询参数
 * @returns 员工列表
 */
export function queryAllEmployee(params?: Record<string, any>) {
  return http.get<EmployeeInfo[]>('/yngy-user/system/sysEmployee/maincenter/queryAllEmployee', {
    ...params,
    t: Date.now(),
  })
}

/**
 * 获取运输方式分页
 * @param data 请求参数
 * @returns 运输方式分页数据
 */
export function getSysOwnerFreightPage(data: OwnerFreightPageRequest) {
  return http.post<OwnerFreightPageResponse>('/yngy-logistics/logistics/ownerFreightType/sysOwnerFreightPage', data, {
    t: Date.now(),
  })
}

// 获取部门下用户列表
export function getDepartUserList(data: {
  pageSize: number
  pageNo: number
  departId?: string
}) {
  return http.get<{ records: UserListResponse[] }>('/yngy-user/sys/user/departUserList', {
    ...data,
    t: Date.now(),
  })
}

/**
 * 获取资金认领详情
 * @param id 认领记录ID
 * @returns 资金认领详情
 */
export function getSysClaimRecordDetails(id: string) {
  return http.get<ReceiptClaimRecordDetails>(`/yngy-logistics/logistics/receiptClaimRecord/sysClaimRecordDetails`, {
    id,
    t: Date.now(),
  })
}

// 导出默认对象，保持向后兼容
export default {
  getUserTenantDepartTree,
  getLogisticsPayTypeDict,
  getInvoiceTypeDict,
  getLogisticsFreightTypeDict,
  getBpmTaskStatusDict,
  queryCompanyNew,
  queryAllEmployee,
  getSysOwnerFreightPage,
  getDepartUserList,
  getPaymentTypeDict,
  getSysClaimRecordDetails,
}
